package org.come.control;

import java.util.ArrayList;
import java.util.List;

import org.come.Frame.FactionMainJframe;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.FactionCardJpanel;
import org.come.action.FromServerAction;
import org.come.bean.GangGiveMoneyBean;
import org.come.bean.GangResultBean;
import org.come.bean.LoginResult;
import org.come.until.FormsManagement;
import org.come.until.GsonUtil;

import com.tool.role.RoleData;
import com.tool.role.RoleProperty;

//TODO 处理捐钱后服务器返回的消息
/**
 * 处理捐钱后服务器返回的消息
 * 
 * @author Administrator
 * 
 */
public class GangGiveMoneyControl implements FromServerAction {
    @Override
    public void controlMessFromServer(String mes, String type) {
    	GangGiveMoneyBean changeBean = GsonUtil.getGsonUtil().getgson().fromJson(mes, GangGiveMoneyBean.class);
    	RoleData.getRoleData().setLoginResult(changeBean.getLoginResult());
    	ZhuFrame.getZhuJpanel().addPrompt2("感谢你为帮派做出的贡献");
    	FactionCardJpanel factionCardJpanel = FactionMainJframe.getFactionMainJframe().getFactionMainJpanel()
                .getFactionCardJpanel();
    	factionCardJpanel.getGangResultBean().setGang(changeBean.getGang());
        GangResultBean gangResultBean = factionCardJpanel.getGangResultBean();
        List<LoginResult> logins = gangResultBean.getRoleTables();
        List<LoginResult> newLogins = new ArrayList<LoginResult>();
        for(LoginResult login : logins) {
        	if(login.getRole_id().compareTo(changeBean.getLoginResult().getRole_id()) == 0){
        		login = changeBean.getLoginResult();
        		newLogins.add(login);
        	} else {
        		newLogins.add(login);
        	}
        }
        gangResultBean.setRoleTables(newLogins);
        factionCardJpanel.getFactionMemberJpanel().showMenuMessage(gangResultBean);
        //刷新帮派抗性，同装备属性
        RoleProperty.ResetBp();
        FormsManagement.HideForm(112);// 隐藏窗体
    }
}
